//
//  RecoverAdDetailViewController.m
//  DreamSoftReimburse
//
//  Created by ZJ on 17/4/15.
//  Copyright © 2017年 ZJ. All rights reserved.
//

#import "RecoverAdDetailViewController.h"
#import "ZJAdditions.h"
#import "PictureChooseView.h"
#import "ZJPhotographSelector.h"
@interface RecoverAdDetailViewController ()<PictureChooseViewDelegate,ZJPhotographSelectorDelegate>
{
    NSData *_data;/** 图片数据流 */
    UILabel *_label;/**< 提示图片 */
    CGFloat _layoutHight;
    PictureChooseView *_selectPictureChooseView;
}
/** 身份证正面 */
@property (nonatomic, strong) PictureChooseView *cardFront;
/** 身份证反面 */
@property (nonatomic, strong) PictureChooseView *cardReverse;
/** 提交按钮 */
@property (nonatomic, strong) UIButton *submit;
/** 图片选择模块 */
@property (nonatomic, strong) ZJPhotographSelector *photographSelector;
@end

@implementation RecoverAdDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor viewBGGrayColor];
    [self photographSelector];
    self.titlelabel.text = @"索回管理权";
    [self setupUI];
    
}
- (void)setupUI{
    //提示标语
    _label =[self cureLabelWithFrame:CGRectMake(0, navHeight + 7 *[UIScreen zj_screenHScale], self.view.width, 20 * [UIScreen zj_screenHScale]) title:@"请拍摄法人身份证" textColor:[UIColor textBlackColor]];
    [self.view addSubview:_label];
    //身份证正面提示
    UILabel *label1 = [self cureLabelWithFrame:CGRectMake(0, _label.bottom, self.view.width, _label.height) title:@"身份证正面" textColor:[UIColor textGrayColor]];
    _layoutHight = label1.bottom;
    [self.view addSubview:label1];
    [self.view addSubview:self.cardFront];
    //身份证背面提示
    UILabel *label2 = [self cureLabelWithFrame:CGRectMake(0, self.cardFront.bottom + 20 * [UIScreen zj_screenHScale], self.view.width, _label.height) title:@"身份证背面" textColor:[UIColor textGrayColor]];
    _layoutHight = label2.bottom;
    [self.view addSubview:label2];
    [self.view addSubview:self.cardReverse];
    [self.view addSubview:self.submit];

}

- (UILabel *)cureLabelWithFrame:(CGRect)frame title:(NSString *)title textColor:(UIColor *)textColor{
    UILabel *label = [[UILabel alloc]initWithFrame:frame];
    label.textColor = textColor;
    label.textAlignment = NSTextAlignmentCenter;
    label.font = [UIFont systemFontOfSize:15 * [UIScreen zj_textFontScale]];
    label.text = title;
    return label;
}
#pragma mark - 点击事件
/** 点击提交 */
- (void)action_submit{
   
    [self netWorking];
}
//索回管理权的网络请求
- (void)netWorking{
    [YJProgressHUD show:@"提交中..." inView:self.view mode:YJProgressModeLoading];
    NSDictionary *dict = @{@"ACCOUNT_ID":self.userModel.ACCOUNT_ID,
                           @"UNIT_ID":self.companyModel.ID,
                           @"MOBILE":self.userModel.MOBILE,
                           @"PHOTO_URL":@"",//
                           @"IDCARD_PHOTO_URL":@"",
                           @"IDCARD_PHOTORE_URL":@"",
                           @"UPLOAD_FILES":@[@{@"FILE_PATH":@"",
                                               @"NAME":@"ENVELOPEPHOTO_URL"},//公函地址
                                             @{@"FILE_PATH":@"",
                                               @"NAME":@"IDCARDPHOTOHAND_URL"}//手持身份证
                                             ]};
    [NetWorkingManager postWithUrlString:[NetWorkingURL unitBack] Parameter:dict Success:^(id object) {
        NetWorkModel *model = [NetWorkModel yy_modelWithJSON:object];
        if ([model.STATE isEqualToString:@"30000"]) {//提交成功
            [YJProgressHUD showMsgWithoutView:@"提交成功"];
        }else{
            [YJProgressHUD showMsgWithoutView:@"提交失败"];
        }
        
    } Fail:^(id object) {
        [YJProgressHUD showMsgWithoutView:@"提交失败"];
    }];

}


#pragma mark - PictureChooseViewDelegate（选择图片） 协议方法
- (void)selectPhotoButtonClick:(PictureChooseView *)pictureChooseView{
    _selectPictureChooseView = pictureChooseView;
    [self.photographSelector corporationClick];
}
#pragma mark UIImagePickerControllerDelegate协议方法

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
    //找到图片
    UIImage *image = info[UIImagePickerControllerOriginalImage];
    _data = UIImageJPEGRepresentation(image, 0.1);
    UIImage *image1 = [UIImage imageWithData:_data];
    _selectPictureChooseView.imageView.image = image1;
    [picker dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark - Setter


#pragma mark - Getters
- (PictureChooseView *)cardFront{
    if (_cardFront == nil){
        _cardFront = [[PictureChooseView alloc] initWithFrame:CGRectMake(12 * [UIScreen zj_screenWScale], _layoutHight, self.view.width - 24 * [UIScreen zj_screenWScale], 190 * [UIScreen zj_screenHScale]) bgImageName:@"img_bg_s" imageName:@"img_card_f"];
        _cardFront.delegate = self;
    }
    return _cardFront;
}

#pragma mark - Getters
- (PictureChooseView *)cardReverse{
    if (_cardReverse == nil){
        _cardReverse = [[PictureChooseView alloc] initWithFrame:CGRectMake(12 * [UIScreen zj_screenWScale], _layoutHight, self.view.width - 24 * [UIScreen zj_screenWScale], 190 * [UIScreen zj_screenHScale]) bgImageName:@"img_bg_s" imageName:@"img_card_b"];
        _cardReverse.delegate = self;
    }
    return _cardReverse;
}

- (UIButton *)submit{
    if (_submit == nil){
        _submit = [[UIButton alloc]initWithFrame:CGRectMake(12 * [UIScreen zj_screenWScale], self.cardReverse.bottom + 30 * [UIScreen zj_screenHScale], self.view.width - 24 * [UIScreen zj_screenWScale], 44 * [UIScreen zj_screenHScale])];
        [_submit setTitle:@"提交" forState:UIControlStateNormal];
        [_submit setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_submit addTarget:self action:@selector(action_submit) forControlEvents:UIControlEventTouchUpInside];
        _submit.sd_cornerRadius = @(_submit.height / 8.0);
        _submit.backgroundColor = [UIColor themeColor];
    }
    return _submit;
}
- (ZJPhotographSelector *)photographSelector{
    if (_photographSelector == nil){
        _photographSelector = [ZJPhotographSelector new];
        _photographSelector.delegate = self;
    }
    return _photographSelector;
}

@end
